package internationalenergytradingplatform.dao;

import internationalenergytradingplatform.pojo.Commodity;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommodityDao {
    /**
     *
     * @author yjh
     * @date 2024/2/13 18:15
     展示所有商品
     */
    @Select("select * from commodity_tb")
    public List<Commodity> getAllCommodity();

    /**
     * 根据ID查询商品
     */
    @Select("select * from commodity_tb where id = #{id}")
    public Commodity getCommodityById(@Param("id") Integer id);


    /**
     *
     * @author yingfeng
     * @date 2024/3/12 16:15
     将商品上架/下架
     */
    @Update("update commodity_tb set commodity_status = #{status} where id = #{id};")
    public void listingProducts(@Param("id") Integer id, @Param("status") Integer status);

    /**
     * 新增商品
     *
     */
    @Insert("insert into commodity_tb values(null, #{name}, #{describe}, #{parameter}," +
            " #{price}, #{unitPrice}, #{inventory}, #{unitInventory}, #{supplierAccount}, " +
            "#{commodityStatus},  #{image1}, #{image2}, #{image3}, #{detailedImages}, #{classification})")
    public void addCommodity(Commodity commodity);

    /**
     * 删除商品FieldSchemaTableType1 idINTERNATIONAL_ENE.. package_tbINT2nameINTERNATIONAL_EN... package_bVAR
     */
    @Delete("delete from commodity_tb where id=#{id}")
    public void deleteCommodity(@Param("id") Integer id);


    /**
     * 修改商品
     * @param commodity
     */
    @Update("update commodity_tb set name = #{name} , " +
            " `describe` = #{describe} , parameter = #{parameter} , " +
            "unit_price = #{unitPrice} , inventory = #{inventory} , " +
            "unit_inventory = #{unitInventory} , image1 = #{image1} , " +
            "image2 = #{image2} , image3 = #{image3} , detailed_images = #{detailedImages} " +
            ", classification = #{classification} where id = #{id};")
    void modifyCommodity(Commodity commodity);

    /**
     *
     * @author yingfeng
     * @date 2024/3/25 18:51
     更新库存
     */
    @Update("update commodity_tb set inventory = #{inventory} where id = #{id}")
    void updateInventory(@Param("inventory") Double inventory, @Param("id") Integer id);
}
